<?php include  APP_PATH.'../template/public/header.php'?>
<aside class="main-sidebar">
    <section class="sidebar">
        <?php include APP_PATH.'../template/public/navigation.php'?>
    </section>
</aside>
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            {$title}
        </h1>

        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> {$title}</a></li>
        </ol>
    </section>
    <section class="content">
        <div class="box box-default">
            <div class="box-body" style="font-size: 12px;">
                <form class="layui-form " action="">
                    <div class="layui-form-item">
                        <h3>广告主信息</h3>
                    </div>
                    <input type="text" name="id" lay-verify="required" class="layui-hide" value="{$agent.id}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入用户名" class="layui-input" disabled value="{$agent.name}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 广告主名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="advertisers_name" lay-verify="required" placeholder="请输入广告主名称" autocomplete="off" class="layui-input" value="{$agent.advertisers_name}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 公司名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="cmopany_name" lay-verify="required" placeholder="请输入公司名称" autocomplete="off" class="layui-input" value="{$agent.cmopany_name}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">行业</label>
                        <div class="layui-input-block">
                            <div class="layui-input-inline">
                                <select name="industry">
                                    <option value="">请选择行业</option>
                                    <option value="浙江" selected="">浙江省</option>
                                    <option value="你的工号">江西省</option>
                                    <option value="你最喜欢的老师">福建省</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 广告来源标识</label>
                        <div class="layui-input-block">
                            <input type="text" name="source_identification" lay-verify="required" placeholder="请输入广告来源标识" autocomplete="off" class="layui-input" value="{$agent.source_identification}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 开户链接</label>
                        <div class="layui-input-block">
                            <input type="text" name="account_url" lay-verify="required" placeholder="请输入开户链接" autocomplete="off" class="layui-input" value="{$agent.account_url}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" name="email" lay-verify="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input" value="{$agent.email}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 品牌名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="brand_name" placeholder="请输入品牌名称" autocomplete="off" class="layui-input" value="{$agent.brand_name}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 影响区域</label>
                        <div class="layui-input-block">
                            <input type="text" name="impact_city"  placeholder="请输入影响区域" autocomplete="off" class="layui-input" value="{$agent.impact_city}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 营销中心所在地</label>
                        <div class="layui-input-block">
                            <input type="text" name="market_adress"  placeholder="请输入营销中心所在地" autocomplete="off" class="layui-input" value="{$agent.market_adress}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 品牌描述</label>
                        <div class="layui-input-block">
                            <input type="text" name="brand_describe"  placeholder="请输入品牌描述" autocomplete="off" class="layui-input" value="{$agent.brand_describe}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 资质证明</label>
                        <input type="hidden" name="aptitude_img" id="aptitude_img"  value="{$agent.aptitude_img}">
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="image1">
                                </div>
                                <button type="button" class="layui-btn layui-btn-primary" id="bannerBtn1"><i class="icon icon-upload3"></i>点击上传图片</button>
                                <p>目前支持 gif | jpg | png 等图片文件上传，文件大小2M以内</p>
                                <p id="demoText1"></p>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 营业执照</label>
                        <input type="hidden" name="license_img" id="license_img"  value="{$agent.license_img}">
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="image2" >
                                </div>
                                <button type="button" class="layui-btn layui-btn-primary" id="bannerBtn2"><i class="icon icon-upload3"></i>点击上传图片</button>
                                <p>目前支持 gif | jpg | png 等图片文件上传，文件大小2M以内</p>
                                <p id="demoText2"></p>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">  营业执照统一社会信用代码</label>
                        <div class="layui-input-block">
                            <input type="text" name="license_code"  lay-verify="required" placeholder=" 营业执照统一社会信用代码" autocomplete="off" class="layui-input"  value="{$agent.license_code}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">  注册地</label>
                        <div class="layui-input-block">
                            <input type="text" name="register_city"  placeholder=" 营业执照统一社会信用代码" autocomplete="off" class="layui-input"  value="{$agent.register_city}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <h3>联系人信息</h3>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">联系人</label>
                            <div class="layui-input-inline">
                                <input type="tel" name="contact"  autocomplete="off" class="layui-input" value="{$agent.contact}">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">联系人手机</label>
                            <div class="layui-input-inline">
                                <input type="tel" name="contact_phone" lay-verify="required|phone" autocomplete="off" class="layui-input" value="{$agent.contact_phone}">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">联系人邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" name="contact_email" lay-verify="email" autocomplete="off" class="layui-input" value="{$agent.contact_email}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="demo1">保存修改</button>
                        </div>
                    </div>
                </form>

            </div>
        </div>
    </section>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        修改密码
                    </h4>
                </div>
                <div class="modal-body">
                    <form class="layui-form" action="">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="exampleInputEmail1">原密码</label>
                                <input name="old_pwd" type="password"  class="layui-input" id="exampleInputEmail1" placeholder="Password">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">新密码</label>
                                <input name="new_pwd" type="password" lay-verify="pass" class="layui-input" id="exampleInputPassword1" placeholder="New Password">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword2">确认密码</label>
                                <input name="new_pwd_check" type="password"  lay-verify="pass" class="layui-input" id="exampleInputPassword2" placeholder="New Password">
                            </div>
                        </div>
                        <div class="box-footer">
                            <button  class="btn btn-primary" lay-submit="" lay-filter="demo2" >保存修改</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        </div>

                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</div>
<?php include APP_PATH.'../template/public/footer.php'; ?>
<script>
    layui.use(['form', 'layedit', 'laydate','upload'], function(){

        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,upload = layui.upload;
        if("{$agent.aptitude_img}"){
            $('#image1').attr('src', '__IMG_PATH__{$agent.aptitude_img}');
            $('#image1').attr('style','height: 350px;width: 220px')
        }
        if("{$agent.license_img}"){
            $('#image2').attr('src', '__IMG_PATH__{$agent.license_img}');
            $('#image2').attr('style','height: 350px;width: 220px')
        }
        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });
        var uploadInst = upload.render({
            elem: '#bannerBtn1'
            ,url: '{:url("admin/UpFiles/upload")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#image1').attr('src', result);
                    $('#image1').attr('style','height: 350px;width: 220px')
                });
            },

            done: function(res){
                if(res.code>0){
                    $('#aptitude_img').val(res.url);
                }else{
                    //如果上传失败
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }

        });
        //
        var uploadInst1 = upload.render({
            elem: '#bannerBtn2'
            ,url: '{:url("admin/UpFiles/upload")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#image2').attr('src', result); //图片链接（base64）
                    $('#image2').attr('style','height: 350px;width: 220px')
                });
            },
            done: function(res){
                if(res.code>0){
                    $('#license_img').val(res.url);
                }else{
                    //如果上传失败
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText2');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst1.upload();
                });
            }
        });
        //监听提交
        form.on('submit(demo1)', function(data){
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post("{:url('')}", data.field, function (res) {
                layer.close(loading);
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                        location.href = res.url;
                    });
                } else {
                    layer.msg(res.msg, {time: 1800, icon: 2});
                }
            });
            return false;
        });
        form.on('submit(demo2)', function(data){
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            if(data.field.new_pwd==data.field.new_pwd_check){
                $.post("{:url('edit_pwd')}", data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            }else{
                layer.close(loading);
                layer.msg('两次输入密码不一致', {time: 1800, icon: 2});
            }
            return false;
        });
    });
</script>
</html>